<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java基本数据类型详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .data-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .type-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            margin-right: 16px;
        }
        .section-title {
            position: relative;
            padding-bottom: 10px;
        }
        .section-title:after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 60px;
            height: 3px;
            background: linear-gradient(to right, #667eea, #764ba2);
        }
        .footer-link:hover {
            color: #a0aec0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight font-serif">探索Java基本数据类型的奥秘</h1>
                    <p class="text-xl mb-8 opacity-90">深入了解Java 8种基本数据类型的特性、内存占用与取值范围</p>
                    <a href="#data-types" class="inline-block bg-white text-indigo-600 font-semibold px-6 py-3 rounded-full hover:bg-gray-100 transition duration-300">
                        <i class="fas fa-arrow-down mr-2"></i>开始学习
                    </a>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="bg-white bg-opacity-20 p-6 rounded-xl backdrop-blur-sm">
                        <div class="mermaid">
                            pie
                                title Java基本数据类型字节占比
                                "byte: 1" : 1
                                "short: 2" : 2
                                "int: 4" : 4
                                "long: 8" : 8
                                "float: 4" : 4
                                "double: 8" : 8
                                "char: 2" : 2
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-6xl px-4 py-16">
        <section id="data-types" class="mb-20">
            <h2 class="text-3xl font-bold mb-12 text-gray-800 section-title">Java基本数据类型详解</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-12">
                <!-- byte -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-blue-500">B</div>
                        <h3 class="text-xl font-bold text-gray-800">byte</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-blue-400"></i> 占用字节: <span class="font-semibold">1 字节 (8 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-blue-400"></i> 取值范围: <span class="font-semibold">-128 到 127</span></li>
                    </ul>
                </div>

                <!-- short -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-green-500">S</div>
                        <h3 class="text-xl font-bold text-gray-800">short</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-green-400"></i> 占用字节: <span class="font-semibold">2 字节 (16 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-green-400"></i> 取值范围: <span class="font-semibold">-32,768 到 32,767</span></li>
                    </ul>
                </div>

                <!-- int -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-purple-500">I</div>
                        <h3 class="text-xl font-bold text-gray-800">int</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-purple-400"></i> 占用字节: <span class="font-semibold">4 字节 (32 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-purple-400"></i> 取值范围: <span class="font-semibold">-2³¹ 到 2³¹-1</span></li>
                    </ul>
                </div>

                <!-- long -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-red-500">L</div>
                        <h3 class="text-xl font-bold text-gray-800">long</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-red-400"></i> 占用字节: <span class="font-semibold">8 字节 (64 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-red-400"></i> 取值范围: <span class="font-semibold">-2⁶³ 到 2⁶³-1</span></li>
                    </ul>
                </div>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                <!-- float -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-yellow-500">F</div>
                        <h3 class="text-xl font-bold text-gray-800">float</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-yellow-400"></i> 占用字节: <span class="font-semibold">4 字节 (32 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-yellow-400"></i> 取值范围: <span class="font-semibold">约 1.4E-45 到 3.4E+38</span></li>
                    </ul>
                </div>

                <!-- double -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-indigo-500">D</div>
                        <h3 class="text-xl font-bold text-gray-800">double</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-indigo-400"></i> 占用字节: <span class="font-semibold">8 字节 (64 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-indigo-400"></i> 取值范围: <span class="font-semibold">约 4.9E-324 到 1.7E+308</span></li>
                    </ul>
                </div>

                <!-- char -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-pink-500">C</div>
                        <h3 class="text-xl font-bold text-gray-800">char</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-pink-400"></i> 占用字节: <span class="font-semibold">2 字节 (16 位)</span></li>
                        <li><i class="fas fa-exchange-alt mr-2 text-pink-400"></i> 取值范围: <span class="font-semibold">0 到 65,535</span></li>
                    </ul>
                </div>

                <!-- boolean -->
                <div class="data-card bg-white rounded-xl shadow-md p-6 transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="type-icon bg-gray-500">B</div>
                        <h3 class="text-xl font-bold text-gray-800">boolean</h3>
                    </div>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-memory mr-2 text-gray-400"></i> 占用字节: <span class="font-semibold">JVM实现相关</span></li>
                        <li><i class="fas fa-info-circle mr-2 text-gray-400"></i> 通常: <span class="font-semibold">1位/1字节</span></li>
                    </ul>
                </div>
            </div>
        </section>

        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">数据类型比较图表</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6">
                    <div class="mermaid">
                        bar
                            title Java基本数据类型占用字节数
                            xAxis 字节数
                            yAxis 数据类型
                            bar byte : 1
                            bar short : 2
                            bar int : 4
                            bar long : 8
                            bar float : 4
                            bar double : 8
                            bar char : 2
                    </div>
                </div>
            </div>
        </section>

        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">使用建议</h2>
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-lightbulb text-yellow-500 mr-3"></i> 选择原则
                        </h3>
                        <ul class="space-y-3 text-gray-700">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i> 根据需求选择最小够用的数据类型</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i> 整数优先考虑int，小数优先考虑double</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i> 仅在明确需要大数时使用long</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i> 处理二进制数据时使用byte</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i> 字符处理必须使用char</li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-exclamation-triangle text-red-500 mr-3"></i> 注意事项
                        </h3>
                        <ul class="space-y-3 text-gray-700">
                            <li><i class="fas fa-times-circle text-red-400 mr-2"></i> 避免不必要的类型转换</li>
                            <li><i class="fas fa-times-circle text-red-400 mr-2"></i> 注意数值溢出问题</li>
                            <li><i class="fas fa-times-circle text-red-400 mr-2"></i> 浮点数比较要小心精度问题</li>
                            <li><i class="fas fa-times-circle text-red-400 mr-2"></i> boolean大小不固定，避免大量使用</li>
                            <li><i class="fas fa-times-circle text-red-400 mr-2"></i> char不能直接当整数使用</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-2xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索编程世界的奥秘</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="footer-link hover:text-white transition duration-300">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#764ba2',
                primaryTextColor: '#fff',
                primaryBorderColor: '#5e3a8f',
                lineColor: '#764ba2',
                textColor: '#333'
            }
        });
    </script>
</body>
</html>